<?php 
if($this->session->userdata('user_id'))
{
    $user_id = $this->session->userdata('user_id');
    $userItem = $this->profile_m->getUser($user_id);
    ?>
    <div class="info-data">
        <a href="<?php echo base_url()."thanh-vien/tai-khoan"?>"><?php if($userItem->image != NULL) { ?>
            <img class="img-responsive img-thumbnail" style="width: 100px; float:left; margin-right: 10px;" src="<?php echo base_url()."assets/images/avatar/".$userItem->image; ?>" alt="<?php echo $userItem->username; ?>" />
            <?php } else { ?>
            <img class="img-responsive img-thumbnail" style="width: 100px; float:left; margin-right: 10px;" src="<?php echo base_url() ?>assets/images/no-avatar.jpg" alt="<?php echo $userItem->username; ?>" />
            <?php } ?>
        </a>
        Xin chào <a href="<?php echo base_url()."thanh-vien/tai-khoan"?>"><b><?php echo $userItem->username; ?></b></a>
        <br/>
        Email: <?php echo $userItem->email ?>
    </div>
    <a href="<?php echo base_url()."thanh-vien/tai-khoan"?>">
        <button type="submit" id="home_login" class="btn btn-default btn-sm">Tài khoản</button>
    </a>
    <a href="<?php echo base_url()."thanh-vien/dang-xuat"?>">
        <button type="submit" id="home_login" class="btn btn-default btn-sm">Đăng xuất</button>
    </a>
    <?php
} 
else 
{ 
    ?>        
    <form class="form-horizontal" action="" method="post" accept-charset="utf-8">
        <div class="form-group">
            <label for="inputEmail3" class="col-sm-4 control-label">Tài khoản: </label>
            <div class="col-sm-8">
                <input type="email" class="form-control input-sm" name="inputEmail3" id="inputEmail3" placeholder="Email">
            </div>
        </div>
        <div class="form-group">
            <label for="inputPassword3" class="col-sm-4 control-label">Mật khẩu: </label>
            <div class="col-sm-8">
                <input type="password" class="form-control input-sm" name="inputPassword3" id="inputPassword3" placeholder="Password">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-4 col-sm-8">
                <button type="submit" id="home_login" class="btn btn-default btn-sm">Đăng nhập</button>                
            </div>
        </div>
    </form>
    <a id="dang-ky" href="<?php echo base_url()."thanh-vien/dang-ky"?>">Đăng ký</a>
    <?php
}
?>


<script type="text/javascript">
    $("#home_login").click(function(){
        var email = $(inputEmail3).val();
        var password = $(inputPassword3).val();
        var AJAX_POST_URL = _base_url + "thanh-vien/dang-nhap";
        console.log(password);
        $.ajax({
            url: AJAX_POST_URL,
            type: "POST",
            data: {
                email: email,
                password: password
            },
            success: function(html)
            {   
                $("#login-form").html(html);
            }
        }); 
        return false;
    });
</script>